<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blogs/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blogs/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blogs/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blogs/images/apple-touch-icon.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/blogs/images/favicon-32x32.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/blogs/images/favicon-16x16.png?v=5.1.3">


  <link rel="mask-icon" href="/blogs/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="Android," />










<meta name="description" content="1.为什么要学习自定义控件？ 我们都知道，安卓官方提供了很多控件，我们可以自由的畅所欲为的使用这些控件去丰富我们的安卓程序，但是有时候，我们遇到一些奇怪的需求的时候，安卓官方提供的控件不满足我们的要求，怎么办？ 这时候，我们就需要自定义控件，既然你没有没那我就自己做一个，这样不就好了吗？ 说干就干，let’s do it   2.学习自定义控件需要会什么？ 需要会使用drawable资源等 需要会">
<meta property="og:type" content="article">
<meta property="og:title" content="Android自定义控件之环形进度条">
<meta property="og:url" content="https://louchaoyy.gitee.io/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/index.html">
<meta property="og:site_name" content="Chao&#39;s blog">
<meta property="og:description" content="1.为什么要学习自定义控件？ 我们都知道，安卓官方提供了很多控件，我们可以自由的畅所欲为的使用这些控件去丰富我们的安卓程序，但是有时候，我们遇到一些奇怪的需求的时候，安卓官方提供的控件不满足我们的要求，怎么办？ 这时候，我们就需要自定义控件，既然你没有没那我就自己做一个，这样不就好了吗？ 说干就干，let’s do it   2.学习自定义控件需要会什么？ 需要会使用drawable资源等 需要会">
<meta property="og:locale">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/ring_1.png">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/ring_2.png">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/ring_3.png">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/ring_4.png">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/ring_5.png">
<meta property="og:image" content="https://louchaoyy.gitee.io/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/ring_6.png">
<meta property="article:published_time" content="2022-03-29T13:48:28.000Z">
<meta property="article:modified_time" content="2022-03-30T14:12:04.745Z">
<meta property="article:author" content="Chaoyxy">
<meta property="article:tag" content="Android">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://louchaoyy.gitee.io/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/ring_1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '',
    scheme: 'Gemini',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://louchaoyy.gitee.io/blogs/2022/03/29/Android自定义控件之环形进度条/"/>





  <title>Android自定义控件之环形进度条 | Chao's blog</title>
  








<meta name="generator" content="Hexo 5.4.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blogs/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Chao's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blogs/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/blogs/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blogs/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://louchaoyy.gitee.io/blogs/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blogs/images/cat.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Chao's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android自定义控件之环形进度条</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2022-03-29T21:48:28+08:00">
                2022-03-29
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2022/03/29/Android自定义控件之环形进度条/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="1-为什么要学习自定义控件？"><a href="#1-为什么要学习自定义控件？" class="headerlink" title="1.为什么要学习自定义控件？"></a>1.为什么要学习自定义控件？</h2><ul>
<li><p>我们都知道，安卓官方提供了很多控件，我们可以自由的畅所欲为的使用这些控件去丰富我们的安卓程序，但是有时候，我们遇到一些奇怪的需求的时候，安卓官方提供的控件不满足我们的要求，怎么办？</p>
<p>这时候，我们就需要自定义控件，既然你没有没那我就自己做一个，这样不就好了吗？</p>
<p>说干就干，<strong>let’s do it</strong></p>
</li>
</ul>
<h2 id="2-学习自定义控件需要会什么？"><a href="#2-学习自定义控件需要会什么？" class="headerlink" title="2.学习自定义控件需要会什么？"></a>2.学习自定义控件需要会什么？</h2><ol>
<li>需要会使用drawable资源等</li>
<li>需要会正常使用Java或者kotlin开发安卓</li>
<li>需要会使用canvas画布对需要的控件进行绘制</li>
<li>需要会使用动画（逐帧动画，补间动画，属性动画等）</li>
</ol>
<h2 id="3-需求描述"><a href="#3-需求描述" class="headerlink" title="3.需求描述"></a>3.需求描述</h2><ul>
<li><p>需要做一个环状的进度条，根据不同的进度显示所占的百分比，要求环状图可以自定义设置一些属性，比如大小，颜色以及文本等</p>
<span id="more"></span></li>
<li><p>样子大概是这样</p>
<img src="/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/ring_1.png" class title="环状图的形状和样子"></li>
<li><p>要求这个环状图能够在各种场景下使用，并且可以改变环状的颜色以及背景颜色，内部能显示当前进度或者占比</p>
</li>
</ul>
<h2 id="4-任务分解"><a href="#4-任务分解" class="headerlink" title="4.任务分解"></a>4.任务分解</h2><p>思路是这样的</p>
<ol>
<li>我们可以用 Android canvas画布画一个圆环</li>
<li>根据不同占比，我们绘制不同角度的圆环</li>
<li>传参的时候，传递数据以及动画的参数</li>
</ol>
<h2 id="5-干"><a href="#5-干" class="headerlink" title="5.干"></a>5.干</h2><h3 id="1-准备资源"><a href="#1-准备资源" class="headerlink" title="1.准备资源"></a>1.准备资源</h3><ul>
<li><p>由于该过程中，我们需要更改属性等，因此我们准备一个xml文件，用来定义属性</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">resources</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">declare-styleable</span> <span class="attr">name</span>=<span class="string">&quot;ringRatioView&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">attr</span> <span class="attr">name</span>=<span class="string">&quot;backWidth&quot;</span> <span class="attr">format</span>=<span class="string">&quot;dimension&quot;</span>/&gt;</span>     <span class="comment">&lt;!--背景圆环宽度--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">attr</span> <span class="attr">name</span>=<span class="string">&quot;progWidth&quot;</span> <span class="attr">format</span>=<span class="string">&quot;dimension&quot;</span>/&gt;</span>     <span class="comment">&lt;!--进度圆环宽度--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">attr</span> <span class="attr">name</span>=<span class="string">&quot;backColor&quot;</span> <span class="attr">format</span>=<span class="string">&quot;color&quot;</span>/&gt;</span>         <span class="comment">&lt;!--背景圆环颜色--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">attr</span> <span class="attr">name</span>=<span class="string">&quot;progColor&quot;</span> <span class="attr">format</span>=<span class="string">&quot;color&quot;</span>/&gt;</span>         <span class="comment">&lt;!--进度圆环颜色--&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">declare-styleable</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">resources</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>我们在这个资源文件中设置将来我们可能用得到的属性</p>
</li>
</ul>
<h3 id="2-开始作画"><a href="#2-开始作画" class="headerlink" title="2.开始作画"></a>2.开始作画</h3><ul>
<li><p>作画之前，我们来考虑一下该如何画</p>
</li>
<li><p>在这里我来介绍一些画布的基础知识</p>
<ol>
<li>我们既然要作画，那么我们肯定要有一个画布</li>
<li>我们有了画布之后我们要知道我们画画的范围</li>
<li>我们有了画布，有了画画的范围，我们要有画笔才能画</li>
<li>万事俱备，只欠东风，我们这里的东风就是“<strong>画画的逻辑</strong>”，我们到底该怎么画？先画什么？再画什么？</li>
</ol>
</li>
<li><p>画画的工具我们可以去自己定义，现在我们先来说一下画画的逻辑。</p>
</li>
<li><p>首先先来认识一下画布，对于一块画布，我们可以想象是这样的，一块画布就是平面直角坐标系的第四象限，从左上角开始出发，横轴往右逐渐增大，纵轴往下逐渐增大。以左上角的顶点为原点（0，0）</p>
</li>
<li><p>那么要画一个圆环，具体怎么画呢？</p>
<p>我们先要知道<strong>圆心</strong>，其次需要知道<strong>半径</strong></p>
</li>
<li><p>那如何确定圆心跟半径呢？别着急，听我慢慢道来</p>
</li>
<li><p>对于一个圆环，我们应该这样确定，我们需要通过正方形来约束圆，我们作圆的半径，如下图</p>
<img src="/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/ring_2.png" class title="通过两个外切正方形来约束圆的半径"></li>
</ul>
<h3 id="3-代码实现canvas画图"><a href="#3-代码实现canvas画图" class="headerlink" title="3.代码实现canvas画图"></a>3.代码实现canvas画图</h3><ul>
<li><p>新建一个<strong>RingRatioView</strong>类 ，继承<strong>View</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.example.myapplication.view;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> android.content.Context;</span><br><span class="line"><span class="keyword">import</span> android.util.AttributeSet;</span><br><span class="line"><span class="keyword">import</span> android.view.View;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> androidx.annotation.Nullable;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RingRatioView</span> <span class="keyword">extends</span> <span class="title">View</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">RingRatioView</span><span class="params">(Context context)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>(context);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">RingRatioView</span><span class="params">(Context context, <span class="meta">@Nullable</span> AttributeSet attrs)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>(context, attrs);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">RingRatioView</span><span class="params">(Context context, <span class="meta">@Nullable</span> AttributeSet attrs, <span class="keyword">int</span> defStyleAttr)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>(context, attrs, defStyleAttr);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>初始化画笔（在构造函数里面进行初始化画笔和设置颜色）</p>
</li>
<li><p>这里使用了自定义属性来进行对资源文件获取</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="title">RingRatioView</span><span class="params">(Context context, <span class="meta">@Nullable</span> AttributeSet attrs)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>(context, attrs);</span><br><span class="line">        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ringRatioView);</span><br><span class="line">        <span class="comment">//外层颜色,默认蓝色</span></span><br><span class="line">        circleColor = typedArray.getColor(R.styleable.ringRatioView_progColor,</span><br><span class="line">                                          context.getColor(R.color.color2));</span><br><span class="line">        <span class="comment">//初始化画笔</span></span><br><span class="line">        <span class="comment">//外层画笔</span></span><br><span class="line">        circlePaint = <span class="keyword">new</span> Paint();</span><br><span class="line">        circlePaint.setAntiAlias(<span class="keyword">true</span>);</span><br><span class="line">        circlePaint.setStyle(Paint.Style.STROKE);</span><br><span class="line">        circlePaint.setColor(circleColor);</span><br><span class="line">        <span class="comment">//背景画笔</span></span><br><span class="line">        backPaint = <span class="keyword">new</span> Paint();</span><br><span class="line">        backPaint.setAntiAlias(<span class="keyword">true</span>);</span><br><span class="line">        backPaint.setStyle(Paint.Style.FILL);</span><br><span class="line">        backPaint.setColor(Color.parseColor(<span class="string">&quot;#909090&quot;</span>));</span><br><span class="line">    </span><br><span class="line">    	currentData = <span class="number">0</span>;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></li>
<li><p>获取画布布局的宽度,我们根据屏幕的宽度确定画布的宽度，我们把画布限制为一个正方形</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">onMeasure</span><span class="params">(<span class="keyword">int</span> widthMeasureSpec, <span class="keyword">int</span> heightMeasureSpec)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">super</span>.onMeasure(widthMeasureSpec, heightMeasureSpec);</span><br><span class="line">    <span class="comment">//获取画布布局的宽度</span></span><br><span class="line">    <span class="keyword">int</span> width = MeasureSpec.getSize(widthMeasureSpec);</span><br><span class="line">    <span class="comment">//画弧线的宽度</span></span><br><span class="line">    circlePaint.setStrokeWidth(width*<span class="number">0.07f</span>);</span><br><span class="line">    <span class="comment">//确定圆弧的举行范围</span></span><br><span class="line">    oval = <span class="keyword">new</span> RectF(width*<span class="number">0.1f</span>,width*<span class="number">0.1f</span>,width*<span class="number">0.9f</span>,width*<span class="number">0.9f</span>);</span><br><span class="line">    <span class="comment">//限制画布比例为正方形（不论布局中对控件设置的高度为多少，都与宽度等长，便可限制为正方形）</span></span><br><span class="line">    <span class="comment">//内圆的方形</span></span><br><span class="line">    smallOval = <span class="keyword">new</span> RectF(width*<span class="number">0.138f</span>,width*<span class="number">0.138f</span>,width*<span class="number">0.862f</span>,width*<span class="number">0.862f</span>);</span><br><span class="line">    setMeasuredDimension(width,width);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>先传递一个值去试试，画成什么样了？</p>
</li>
<li><p>画个60度的圆形试试</p>
<img src="/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/ring_3.png" class title="暂时很粗糙是这样的"></li>
<li><p><strong>这样会存在一个问题</strong></p>
<p>我要传的值是60，实际上我想要得到的值是60%，因为我想要得到一个所占百分比情况，而圆环直接给我画了60°，显然是不合理的，我们应该画360°的60%，所以我们应该把360°分成100份，每1%为3.6°，因此得到计算公式</p>
<p><code>currentData = (float)360/100*data</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* 画白色圆弧</span></span><br><span class="line"><span class="comment">* <span class="doctag">@param</span> canvas</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">drawCircle</span><span class="params">(Canvas canvas)</span> </span>&#123;</span><br><span class="line">    canvas.save();</span><br><span class="line">    canvas.drawArc(smallOval,<span class="number">270</span>,currentData*<span class="number">3.6f</span>,<span class="keyword">false</span>,circlePaint);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>得到的效果是这样的</p>
<img src="/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/ring_4.png" class title="正确的60%的占比"></li>
</ul>
<h3 id="4-设置动画属性"><a href="#4-设置动画属性" class="headerlink" title="4.设置动画属性"></a>4.设置动画属性</h3><ul>
<li><p>这个圆环暂时非常粗糙，我们想要体验好一点，我们应该设置一下动画，就是让他在比例增加的过程中，有个增长的过程，这就用到了属性动画</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"> <span class="comment">//动态变化数据</span></span><br><span class="line"><span class="comment">//通过属性动画修改currentData的数值，就可以将箭头和数值做动态处理了</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setPercentData</span><span class="params">(<span class="keyword">final</span> <span class="keyword">float</span> data, DecelerateInterpolator interpolator)</span></span>&#123;</span><br><span class="line">    ValueAnimator valueAnimator = ValueAnimator.ofFloat(currentData,data);</span><br><span class="line">    valueAnimator.setDuration((<span class="keyword">long</span>)(Math.abs(currentData-data)*<span class="number">20</span>));</span><br><span class="line">    valueAnimator.addUpdateListener(<span class="keyword">new</span> ValueAnimator.AnimatorUpdateListener() &#123;</span><br><span class="line">        <span class="meta">@Override</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onAnimationUpdate</span><span class="params">(ValueAnimator valueAnimator)</span> </span>&#123;</span><br><span class="line">            <span class="keyword">float</span> value = (<span class="keyword">float</span>)valueAnimator.getAnimatedValue();</span><br><span class="line">            currentData = (<span class="keyword">float</span>) (Math.round(value*<span class="number">10</span>))/<span class="number">10</span>;</span><br><span class="line">            invalidate();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">    valueAnimator.setInterpolator(interpolator);</span><br><span class="line">    valueAnimator.start();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这个属性动画，我们可以在构造函数中去设置初始值，设置为0，也就是说从0增长到data的情况，我们设置一个过渡时间，假设根据0-data开始变化，是这段时间差的20倍毫秒，通过这一行代码实现</p>
<img src="/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/ring_5.png" class title="设置动画时长"></li>
</ul>
<h3 id="5-开始画文本内容"><a href="#5-开始画文本内容" class="headerlink" title="5.开始画文本内容"></a>5.开始画文本内容</h3><ul>
<li><p>现在还缺少文本内容，我们需要绘制文本内容，那么此时我们来定义两支画笔，一支用于绘制背景标题，一支用于绘制数值变化情况</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">titlePaint = <span class="keyword">new</span> Paint();</span><br><span class="line">titlePaint.setAntiAlias(<span class="keyword">true</span>);</span><br><span class="line">titlePaint.setStyle(Paint.Style.FILL_AND_STROKE);</span><br><span class="line">titlePaint.setColor(Color.parseColor(<span class="string">&quot;#FFFFFF&quot;</span>));</span><br><span class="line">titlePaint.setTextSize(<span class="number">40</span>);</span><br><span class="line"><span class="comment">//数据</span></span><br><span class="line">dataPaint = <span class="keyword">new</span> Paint();</span><br><span class="line">dataPaint.setAntiAlias(<span class="keyword">true</span>);</span><br><span class="line">dataPaint.setStyle(Paint.Style.FILL_AND_STROKE);</span><br><span class="line">dataPaint.setColor(Color.parseColor(<span class="string">&quot;#FF000000&quot;</span>));</span><br><span class="line">dataPaint.setTextSize(<span class="number">40</span>);</span><br></pre></td></tr></table></figure></li>
<li><p>绘制文本</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* 绘制标题和数据</span></span><br><span class="line"><span class="comment">* <span class="doctag">@param</span> canvas</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">drawTitleData</span><span class="params">(Canvas canvas)</span> </span>&#123;</span><br><span class="line">    canvas.save();</span><br><span class="line">    <span class="keyword">int</span> width = canvas.getWidth();</span><br><span class="line">    <span class="comment">//标题</span></span><br><span class="line">    canvas.drawText(<span class="string">&quot;潍坊占比&quot;</span>,width*<span class="number">0.30f</span>,width*<span class="number">0.43f</span>,titlePaint);</span><br><span class="line">    canvas.drawText(currentData+<span class="string">&quot;%&quot;</span>,width*<span class="number">0.36f</span>,width*<span class="number">0.57f</span>,dataPaint);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这里我更改了画笔尺寸，各位可以根据自己实际情况更改合适的尺寸</p>
<p>这两行代码的目的是调整数据所在的位置，需要经过不止一次的调整，要有耐心</p>
<p>绘制过程终于结束了，效果如何？</p>
<p>请看下图：</p>
<img src="/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/ring_6.png" class title="完工"></li>
</ul>
<h3 id="6-如何使用？"><a href="#6-如何使用？" class="headerlink" title="6.如何使用？"></a>6.如何使用？</h3><ul>
<li><p>有同学要问了，那你既然绘制好了，怎么去使用呢？</p>
</li>
<li><p>不着急，听我道来</p>
<p><strong>首先，我们这个是个自定义控件</strong></p>
<p>那么我们就可以在布局文件中去使用，如下</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">LinearLayout</span> <span class="attr">xmlns:android</span>=<span class="string">&quot;http://schemas.android.com/apk/res/android&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:app</span>=<span class="string">&quot;http://schemas.android.com/apk/res-auto&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:tools</span>=<span class="string">&quot;http://schemas.android.com/tools&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:orientation</span>=<span class="string">&quot;vertical&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">tools:context</span>=<span class="string">&quot;.MainActivity&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">com.example.myapplication.view.RingRatioView</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/ringRatioView&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_gravity</span>=<span class="string">&quot;center&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:progColor</span>=<span class="string">&quot;#983BC9&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">LinearLayout</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p><strong>其次，</strong>我们在acivity或者fragment中使用时如下</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//拿到控件</span></span><br><span class="line"><span class="meta">@BindView(R.id.ringRatioView)</span></span><br><span class="line">RingRatioView ringRatioView;</span><br><span class="line"><span class="comment">//调用函数，传递两个参数，第一个参数是我们要传递的数据，第二个参数是一个回调函数，设置动画</span></span><br><span class="line">ringRatioView.setPercentData(<span class="number">60</span>,<span class="keyword">new</span> DecelerateInterpolator());</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="6-所有代码"><a href="#6-所有代码" class="headerlink" title="6.所有代码"></a>6.所有代码</h2><h3 id="1-控件代码："><a href="#1-控件代码：" class="headerlink" title="1.控件代码："></a>1.控件代码：</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.example.myapplication.view;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> android.animation.ValueAnimator;</span><br><span class="line"><span class="keyword">import</span> android.content.Context;</span><br><span class="line"><span class="keyword">import</span> android.content.res.TypedArray;</span><br><span class="line"><span class="keyword">import</span> android.graphics.Canvas;</span><br><span class="line"><span class="keyword">import</span> android.graphics.Color;</span><br><span class="line"><span class="keyword">import</span> android.graphics.Paint;</span><br><span class="line"><span class="keyword">import</span> android.graphics.RectF;</span><br><span class="line"><span class="keyword">import</span> android.util.AttributeSet;</span><br><span class="line"><span class="keyword">import</span> android.view.View;</span><br><span class="line"><span class="keyword">import</span> android.view.animation.DecelerateInterpolator;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> androidx.annotation.Nullable;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.example.myapplication.R;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RingRatioView</span> <span class="keyword">extends</span> <span class="title">View</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//矩形宽度</span></span><br><span class="line">    <span class="keyword">private</span> RectF oval;</span><br><span class="line">    <span class="comment">//外层环状画笔</span></span><br><span class="line">    <span class="keyword">private</span> Paint circlePaint;</span><br><span class="line">    <span class="comment">//外层颜色</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> circleColor;</span><br><span class="line">    <span class="comment">//背景画笔</span></span><br><span class="line">    <span class="keyword">private</span> Paint backPaint;</span><br><span class="line">    <span class="comment">//定义数据</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">float</span> data;</span><br><span class="line">    <span class="comment">//内圆</span></span><br><span class="line">    <span class="keyword">private</span> RectF smallOval;</span><br><span class="line">    <span class="comment">//初始数据</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">float</span> currentData;</span><br><span class="line">    <span class="comment">//绘制文本标题</span></span><br><span class="line">    <span class="keyword">private</span> Paint titlePaint;</span><br><span class="line">    <span class="comment">//绘制变化数据</span></span><br><span class="line">    <span class="keyword">private</span> Paint dataPaint;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">RingRatioView</span><span class="params">(Context context)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>(context);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">RingRatioView</span><span class="params">(Context context, <span class="meta">@Nullable</span> AttributeSet attrs)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>(context, attrs);</span><br><span class="line">        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ringRatioView);</span><br><span class="line">        <span class="comment">//外层颜色,默认蓝色</span></span><br><span class="line">        circleColor = typedArray.getColor(R.styleable.ringRatioView_progColor,context.getColor(R.color.color2));</span><br><span class="line">        <span class="comment">//初始化画笔</span></span><br><span class="line">        <span class="comment">//外层画笔</span></span><br><span class="line">        circlePaint = <span class="keyword">new</span> Paint();</span><br><span class="line">        circlePaint.setAntiAlias(<span class="keyword">true</span>);</span><br><span class="line">        circlePaint.setStyle(Paint.Style.STROKE);</span><br><span class="line">        circlePaint.setColor(circleColor);</span><br><span class="line">        <span class="comment">//背景画笔</span></span><br><span class="line">        backPaint = <span class="keyword">new</span> Paint();</span><br><span class="line">        backPaint.setAntiAlias(<span class="keyword">true</span>);</span><br><span class="line">        backPaint.setStyle(Paint.Style.FILL);</span><br><span class="line">        backPaint.setColor(Color.parseColor(<span class="string">&quot;#909090&quot;</span>));</span><br><span class="line">        <span class="comment">//标题</span></span><br><span class="line">        titlePaint = <span class="keyword">new</span> Paint();</span><br><span class="line">        titlePaint.setAntiAlias(<span class="keyword">true</span>);</span><br><span class="line">        titlePaint.setStyle(Paint.Style.FILL_AND_STROKE);</span><br><span class="line">        titlePaint.setColor(Color.parseColor(<span class="string">&quot;#FFFFFF&quot;</span>));</span><br><span class="line">        titlePaint.setTextSize(<span class="number">100</span>);</span><br><span class="line">        <span class="comment">//数据</span></span><br><span class="line">        dataPaint = <span class="keyword">new</span> Paint();</span><br><span class="line">        dataPaint.setAntiAlias(<span class="keyword">true</span>);</span><br><span class="line">        dataPaint.setStyle(Paint.Style.FILL_AND_STROKE);</span><br><span class="line">        dataPaint.setColor(Color.parseColor(<span class="string">&quot;#FF000000&quot;</span>));</span><br><span class="line">        dataPaint.setTextSize(<span class="number">120</span>);</span><br><span class="line">        currentData = <span class="number">0</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">RingRatioView</span><span class="params">(Context context, <span class="meta">@Nullable</span> AttributeSet attrs, <span class="keyword">int</span> defStyleAttr)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>(context, attrs, defStyleAttr);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">onMeasure</span><span class="params">(<span class="keyword">int</span> widthMeasureSpec, <span class="keyword">int</span> heightMeasureSpec)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>.onMeasure(widthMeasureSpec, heightMeasureSpec);</span><br><span class="line">        <span class="comment">//获取画布布局的宽度</span></span><br><span class="line">        <span class="keyword">int</span> width = MeasureSpec.getSize(widthMeasureSpec);</span><br><span class="line">        <span class="comment">//画弧线的宽度</span></span><br><span class="line">        circlePaint.setStrokeWidth(width*<span class="number">0.07f</span>);</span><br><span class="line">        <span class="comment">//确定圆弧的举行范围</span></span><br><span class="line">        oval = <span class="keyword">new</span> RectF(width*<span class="number">0.1f</span>,width*<span class="number">0.1f</span>,width*<span class="number">0.9f</span>,width*<span class="number">0.9f</span>);</span><br><span class="line">        <span class="comment">//限制画布比例为正方形（不论布局中对控件设置的高度为多少，都与宽度等长，便可限制为正方形）</span></span><br><span class="line">        <span class="comment">//内圆的方形</span></span><br><span class="line">        smallOval = <span class="keyword">new</span> RectF(width*<span class="number">0.138f</span>,width*<span class="number">0.138f</span>,width*<span class="number">0.862f</span>,width*<span class="number">0.862f</span>);</span><br><span class="line">        setMeasuredDimension(width,width);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">onDraw</span><span class="params">(Canvas canvas)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>.onDraw(canvas);</span><br><span class="line">        <span class="comment">//画背景</span></span><br><span class="line">        drawBack(canvas);</span><br><span class="line">        <span class="comment">//画圆环</span></span><br><span class="line">        drawCircle(canvas);</span><br><span class="line">        <span class="comment">//绘制标题和数据</span></span><br><span class="line">        drawTitleData(canvas);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 画背景</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> canvas</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">drawBack</span><span class="params">(Canvas canvas)</span></span>&#123;</span><br><span class="line">        canvas.save();</span><br><span class="line">        canvas.drawArc(oval,<span class="number">0</span>,<span class="number">360</span>,<span class="keyword">false</span>,backPaint);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 画白色圆弧</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> canvas</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">drawCircle</span><span class="params">(Canvas canvas)</span> </span>&#123;</span><br><span class="line">        canvas.save();</span><br><span class="line">        canvas.drawArc(smallOval,<span class="number">270</span>,currentData*<span class="number">3.6f</span>,<span class="keyword">false</span>,circlePaint);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//动态变化数据</span></span><br><span class="line">    <span class="comment">//通过属性动画修改currentData的数值，就可以将箭头和数值做动态处理了</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setPercentData</span><span class="params">(<span class="keyword">final</span> <span class="keyword">float</span> data, DecelerateInterpolator interpolator)</span></span>&#123;</span><br><span class="line">        ValueAnimator valueAnimator = ValueAnimator.ofFloat(currentData,data);</span><br><span class="line">        valueAnimator.setDuration((<span class="keyword">long</span>)(Math.abs(currentData-data)*<span class="number">20</span>));</span><br><span class="line">        valueAnimator.addUpdateListener(<span class="keyword">new</span> ValueAnimator.AnimatorUpdateListener() &#123;</span><br><span class="line">            <span class="meta">@Override</span></span><br><span class="line">            <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onAnimationUpdate</span><span class="params">(ValueAnimator valueAnimator)</span> </span>&#123;</span><br><span class="line">                <span class="keyword">float</span> value = (<span class="keyword">float</span>)valueAnimator.getAnimatedValue();</span><br><span class="line">                currentData = (<span class="keyword">float</span>) (Math.round(value*<span class="number">10</span>))/<span class="number">10</span>;</span><br><span class="line">                invalidate();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">        valueAnimator.setInterpolator(interpolator);</span><br><span class="line">        valueAnimator.start();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * 绘制标题和数据</span></span><br><span class="line"><span class="comment">         * <span class="doctag">@param</span> canvas</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">drawTitleData</span><span class="params">(Canvas canvas)</span> </span>&#123;</span><br><span class="line">            canvas.save();</span><br><span class="line">            <span class="keyword">int</span> width = canvas.getWidth();</span><br><span class="line">            <span class="comment">//标题</span></span><br><span class="line">            canvas.drawText(<span class="string">&quot;潍坊占比&quot;</span>,width*<span class="number">0.30f</span>,width*<span class="number">0.43f</span>,titlePaint);</span><br><span class="line">            canvas.drawText(currentData+<span class="string">&quot;%&quot;</span>,width*<span class="number">0.36f</span>,width*<span class="number">0.57f</span>,dataPaint);</span><br><span class="line">        &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="2-资源文件"><a href="#2-资源文件" class="headerlink" title="2.资源文件"></a>2.资源文件</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">resources</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">declare-styleable</span> <span class="attr">name</span>=<span class="string">&quot;ringRatioView&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">attr</span> <span class="attr">name</span>=<span class="string">&quot;backWidth&quot;</span> <span class="attr">format</span>=<span class="string">&quot;dimension&quot;</span>/&gt;</span>     <span class="comment">&lt;!--背景圆环宽度--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">attr</span> <span class="attr">name</span>=<span class="string">&quot;progWidth&quot;</span> <span class="attr">format</span>=<span class="string">&quot;dimension&quot;</span>/&gt;</span>     <span class="comment">&lt;!--进度圆环宽度--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">attr</span> <span class="attr">name</span>=<span class="string">&quot;backColor&quot;</span> <span class="attr">format</span>=<span class="string">&quot;color&quot;</span>/&gt;</span>         <span class="comment">&lt;!--背景圆环颜色--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">attr</span> <span class="attr">name</span>=<span class="string">&quot;progColor&quot;</span> <span class="attr">format</span>=<span class="string">&quot;color&quot;</span>/&gt;</span>         <span class="comment">&lt;!--进度圆环颜色--&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">declare-styleable</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">resources</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="3-布局文件"><a href="#3-布局文件" class="headerlink" title="3.布局文件"></a>3.布局文件</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">LinearLayout</span> <span class="attr">xmlns:android</span>=<span class="string">&quot;http://schemas.android.com/apk/res/android&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:app</span>=<span class="string">&quot;http://schemas.android.com/apk/res-auto&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:tools</span>=<span class="string">&quot;http://schemas.android.com/tools&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;match_parent&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:orientation</span>=<span class="string">&quot;vertical&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">tools:context</span>=<span class="string">&quot;.MainActivity&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">com.example.myapplication.view.RingRatioView</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">&quot;@+id/ringRatioView&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">&quot;wrap_content&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_gravity</span>=<span class="string">&quot;center&quot;</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:progColor</span>=<span class="string">&quot;#983BC9&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">LinearLayout</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="4-MainActivity"><a href="#4-MainActivity" class="headerlink" title="4.MainActivity"></a>4.MainActivity</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.example.myapplication;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> androidx.appcompat.app.AppCompatActivity;</span><br><span class="line"><span class="keyword">import</span> androidx.recyclerview.widget.LinearLayoutManager;</span><br><span class="line"><span class="keyword">import</span> androidx.recyclerview.widget.RecyclerView;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> android.os.Bundle;</span><br><span class="line"><span class="keyword">import</span> android.view.animation.DecelerateInterpolator;</span><br><span class="line"><span class="keyword">import</span> com.example.myapplication.view.RingRatioView;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.w3c.dom.Text;</span><br><span class="line"><span class="keyword">import</span> butterknife.BindView;</span><br><span class="line"><span class="keyword">import</span> butterknife.ButterKnife;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MainActivity</span> <span class="keyword">extends</span> <span class="title">AppCompatActivity</span> </span>&#123;</span><br><span class="line">    </span><br><span class="line">    <span class="meta">@BindView(R.id.ringRatioView)</span></span><br><span class="line">    RingRatioView ringRatioView;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> progressNum = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">onCreate</span><span class="params">(Bundle savedInstanceState)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">super</span>.onCreate(savedInstanceState);</span><br><span class="line">        setContentView(R.layout.activity_main);</span><br><span class="line">        ButterKnife.bind(<span class="keyword">this</span>);</span><br><span class="line">        ringRatioView.setPercentData(<span class="number">60</span>,<span class="keyword">new</span> DecelerateInterpolator());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;   </span><br></pre></td></tr></table></figure>

<ul>
<li>至此，你要说你没看懂都说不过去了吧</li>
</ul>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="http://chaoyxy.cn/data/User/admin/home/desktop/images/alipay.jpg" alt=" 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="http://chaoyxy.cn/data/User/admin/home/desktop/images/wechatpay.jpg" alt=" 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blogs/tags/Android/" rel="tag"># Android</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blogs/2022/03/18/vue%E5%8F%8C%E5%90%91%E6%95%B0%E6%8D%AE%E7%BB%91%E5%AE%9A%E5%8E%9F%E7%90%86%E8%A7%A3%E6%9E%90/" rel="next" title="vue双向数据绑定原理解析(源代码在文章末尾)">
                <i class="fa fa-chevron-left"></i> vue双向数据绑定原理解析(源代码在文章末尾)
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blogs/2022/04/23/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E6%97%B6%E9%97%B4%E9%80%89%E6%8B%A9%E5%99%A8/" rel="prev" title="WXminiProgram时间选择器">
                WXminiProgram时间选择器 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a target="_blank" rel="noopener" href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blogs/images/cat.jpg"
                alt="" />
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blogs/archives">
              
                  <span class="site-state-item-count">43</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blogs/tags/index.html">
                  <span class="site-state-item-count">10</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://gitee.com/louchaoyy" target="_blank" title="Gitee">
                      
                        <i class="fa fa-fw fa-gitee"></i>Gitee</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="louchao@louchaoyy.cn" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E5%AD%A6%E4%B9%A0%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%EF%BC%9F"><span class="nav-number">1.</span> <span class="nav-text">1.为什么要学习自定义控件？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%AD%A6%E4%B9%A0%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E9%9C%80%E8%A6%81%E4%BC%9A%E4%BB%80%E4%B9%88%EF%BC%9F"><span class="nav-number">2.</span> <span class="nav-text">2.学习自定义控件需要会什么？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E9%9C%80%E6%B1%82%E6%8F%8F%E8%BF%B0"><span class="nav-number">3.</span> <span class="nav-text">3.需求描述</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E4%BB%BB%E5%8A%A1%E5%88%86%E8%A7%A3"><span class="nav-number">4.</span> <span class="nav-text">4.任务分解</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E5%B9%B2"><span class="nav-number">5.</span> <span class="nav-text">5.干</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E5%87%86%E5%A4%87%E8%B5%84%E6%BA%90"><span class="nav-number">5.1.</span> <span class="nav-text">1.准备资源</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E5%BC%80%E5%A7%8B%E4%BD%9C%E7%94%BB"><span class="nav-number">5.2.</span> <span class="nav-text">2.开始作画</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0canvas%E7%94%BB%E5%9B%BE"><span class="nav-number">5.3.</span> <span class="nav-text">3.代码实现canvas画图</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-%E8%AE%BE%E7%BD%AE%E5%8A%A8%E7%94%BB%E5%B1%9E%E6%80%A7"><span class="nav-number">5.4.</span> <span class="nav-text">4.设置动画属性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-%E5%BC%80%E5%A7%8B%E7%94%BB%E6%96%87%E6%9C%AC%E5%86%85%E5%AE%B9"><span class="nav-number">5.5.</span> <span class="nav-text">5.开始画文本内容</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%EF%BC%9F"><span class="nav-number">5.6.</span> <span class="nav-text">6.如何使用？</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E6%89%80%E6%9C%89%E4%BB%A3%E7%A0%81"><span class="nav-number">6.</span> <span class="nav-text">6.所有代码</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E6%8E%A7%E4%BB%B6%E4%BB%A3%E7%A0%81%EF%BC%9A"><span class="nav-number">6.1.</span> <span class="nav-text">1.控件代码：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-%E8%B5%84%E6%BA%90%E6%96%87%E4%BB%B6"><span class="nav-number">6.2.</span> <span class="nav-text">2.资源文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E5%B8%83%E5%B1%80%E6%96%87%E4%BB%B6"><span class="nav-number">6.3.</span> <span class="nav-text">3.布局文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-MainActivity"><span class="nav-number">6.4.</span> <span class="nav-text">4.MainActivity</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Chaoyxy</span>

  
</div>

<span id="busuanzi_container_site_pv">
    本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>
<!--

  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.3</div>
-->




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/blogs/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/blogs/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/blogs/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/blogs/js/src/motion.js?v=5.1.3"></script>



  
  


  <script type="text/javascript" src="/blogs/js/src/affix.js?v=5.1.3"></script>

  <script type="text/javascript" src="/blogs/js/src/schemes/pisces.js?v=5.1.3"></script>



  
  <script type="text/javascript" src="/blogs/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/blogs/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/blogs/js/src/bootstrap.js?v=5.1.3"></script>



  


  

    
      <script id="dsq-count-scr" src="https://Chaoyxy.disqus.com/count.js" async></script>
    

    
      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'https://louchaoyy.gitee.io/blogs/2022/03/29/Android%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8E%A7%E4%BB%B6%E4%B9%8B%E7%8E%AF%E5%BD%A2%E8%BF%9B%E5%BA%A6%E6%9D%A1/';
          this.page.identifier = '2022/03/29/Android自定义控件之环形进度条/';
          this.page.title = 'Android自定义控件之环形进度条';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://Chaoyxy.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>
    

  




	





  














  





  

  

  

  
  

  

  

  

</body>
</html>
